<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>item列表</title>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">

    <!-- 可选的Bootstrap主题文件（一般不用引入） -->
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="http://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<form role="form" class="form-horizontal">
    <div class="form-group">
        <label for="itemName" class="col-sm-5 control-label">项目</label>

        <div class="col-sm-3">
            <input type="text" class="form-control" id="itemName" placeholder="请输项目" required autofocus>
        </div>

        <label for="itemKey" class="col-sm-5 control-label">账号</label>

        <div class="col-sm-3">
            <input type="text" class="form-control" id="itemKey" placeholder="请输入账号" required>
        </div>

        <label for="itemSecret" class="col-sm-5 control-label">密码</label>

        <div class="col-sm-3">
            <input type="password" class="form-control" id="itemSecret" placeholder="请输入密码" required>
        </div>
    </div>
    <div class="row">
        <div class="col-md-3 col-sm-offset-5 ">
            <button type="button" id="sure" class="btn btn-primary btn-block">确认</button>
        </div>
    </div>
</form>
</body>
<script type="text/javascript">
    $(
            document.onkeydown = function (e) {
                var ev = document.all ? window.event : e;
                if (ev.keyCode == 13) {
                    $("#sure").click();
                }
            }
    );

    $("#sure").click(function () {
        sure();
    });

    function sure() {
        $.ajax({
            url: '/item/add',// 跳转到 action
            headers: {'Content-type': 'application/json;charset=UTF-8'},//传入数据数据格式 json
            data: JSON.stringify({
                itemName: $("#itemName").val(),
                itemKey: $("#itemKey").val(),
                itemSecret: $("#itemSecret").val()
            }),
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                if (data.statusCode == 0) {
                    location.href = "/html/item/itemList.html";
                } else {
                    //noinspection JSUnresolvedVariable
                    alert(data.statusMessage);
                }
            },
            error: function () {
                // view("异常！");
                alert("服务器感冒了！");
            }
        });
    }
</script>
</html>